package redisx

import (
	"fmt"

	"github.com/redis/go-redis/v9"
)

type LockGenerator struct {
	cl         redis.UniversalClient
	lockConfig *Cfg
	format     string
}

func NewRedisLockGenerator(cl redis.UniversalClient, lockConfig *Cfg, format string) *LockGenerator {
	return &LockGenerator{cl: cl, lockConfig: lockConfig, format: format}
}

func (r *LockGenerator) GenLock(id uint64) *RedisLock {
	key := fmt.Sprintf(r.format, id)
	return NewRedisLock(r.cl, key, r.lockConfig)
}

func (r *LockGenerator) GenLockString(id string) *RedisLock {
	key := fmt.Sprintf(r.format, id)
	return NewRedisLock(r.cl, key, r.lockConfig)
}
